using System;
using System.Collections.Generic;
using System.Text;
using JobShopModel.Events;
using Extern.Tools;

namespace JobShopModel.Model.FactoryLvl
{
    /// <summary>
    /// Keep track and store all the events of the simulation.
    /// Each events are ordered depending on their StatingTime
    /// <seealso cref="IEvent"/>
    /// </summary>
    public class EventQueue
    {
        private Extern.MinHeap<IEvent> minheap;
        //heap used for the event queue

        /// <summary>
        /// Constructor - takes a list as an argument and then sorts the list into
        /// a binary heap with the minimum (soonest) event at the first index.  This allows
        /// the heap to be built faster than inserting each event individually
        /// </summary>
        /// <param name="inList">List of events (to be sorted by heap)</param>
        public EventQueue(List<IEvent> inList)
        {
            this.minheap = new JobShopModel.Extern.MinHeap<IEvent>(inList);
        }

        /// <summary>
        /// Get the next event
        /// </summary>
        /// <returns>The event whose timestamp is soonest</returns>
        public IEvent nextEvent()
        {
            return minheap.heapPop();
        }

        /// <summary>
        /// Checks whether the queue is empty
        /// </summary>
        /// <returns>True if empty, false otherwise</returns>
        public bool isEmpty()
        {
            return (minheap.Count == 0);
        }

        /// <summary>
        /// Add an event to the queue
        /// </summary>
        /// <param name="inEvent">Event to be added</param>
        public void insertEvent(IEvent inEvent)
        {
            minheap.insert(inEvent);
        }
    }
}


